<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
		<div id="mainownservice">
			<h3><?php echo JText::_('OWNSERVICE_REQUEST_APPROVEL'); ?></h3>
			<hr />
			<script language="javascript" type="text/javascript">
				<!--
					function submitbutton(pressbutton)
					{
						var form = document.adminForm;

						if (form.boxchecked.value == 0){
							alert( "<?php echo JText::_( 'OWNSERVICE_SELECT_REQUEST_APPROVEL', true ); ?>" );
						} else {
							submitform( pressbutton );
						}
					}
				//-->
			</script>
			<div id="toolbar">
				<a class="toolbar" onclick="submitbutton('elementrequestapproval');" href="#">
					<span title="<?php echo JText::_('OWNSERVICE_REQUEST_APPROVEL'); ?>" class="icon-32-forward"></span>
					<?php echo JText::_('OWNSERVICE_APPROVE_AND_SELECT_IR'); ?>
				</a>
			</div>
			<div class="clear"> </div>
			<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm">
				<table>
					<tr>
						<td width="100%">
							<?php echo JText::_( 'OWNSERVICE_FILTER' ); ?>:<input type="text" name="search" value="<?php echo htmlspecialchars($this->lists['search']);?>"  onchange="document.adminForm.submit();" />
							<button onclick="this.form.submit();" class="button">
								<?php echo JText::_( 'Go' ); ?>
							</button>
							<button onclick="document.adminForm.search.value='';this.form.submit();" class="button">
								<?php echo JText::_( 'Reset' ); ?>
							</button>
						</td>
						<td nowrap="nowrap">
							<?php echo $this->lists['branch']; ?> <?php /*echo $this->lists['time'];*/ ?>
						</td>
					</tr>
				</table>
				<table class="adminlist" cellspacing="1">
					<tr>
						<td align="center" class="tablelist">
							<?php echo JText::_('NUM'); ?>
						</td>
						<td align="center" class="tablelist">
							<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->rows); ?>);" />
						</td>
						<td align="center" class="tablelist" width="10%">
							<?php /*echo JText::_('OWNSERVICE_RECEIVER_NO');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_RECEIVER_NO', 't.invoice', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php /*echo JText::_('OWNSERVICE_ACCOUNT_NO');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_ACCOUNT_NO', 't.account', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist" width="10%">
							<?php /*echo JText::_('OWNSERVICE_BANK_NAME');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_BANK_NAME', 'a.bank_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php /*echo JText::_('OWNSERVICE_BRANCH_CITY');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_BRANCH_CITY', 'a.branch_city', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist" width="10%">
							<?php /*echo JText::_('OWNSERVICE_BRANCH_NAME');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_BRANCH_NAME', 'a.branch_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php /*echo JText::_('OWNSERVICE_USER');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_USER', 'u.username', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist" width="85" nowrap="nowrap">
							<?php /*echo JText::_('OWNSERVICE_TRANSFER_ON');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_TRANSFER_ON', 't.requested_date', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist" width="10%">
							<?php /*echo JText::_('OWNSERVICE_AMOUNT_TRANSFER');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_AMOUNT_TRANSFER', 't.amount', $this->lists['order_Dir'], $this->lists['order'] ); ?>
							<br />(AUD)
						</td>
						<td align="center" class="tablelist" width="10%" nowrap="nowrap">
							<?php /*echo JText::_('OWNSERVICE_RATE');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_RATE', 't.rate', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist" width="10%">
							<?php /*echo JText::_('OWNSERVICE_TOTAL_EXCHANGE');*/ ?>
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_TOTAL_EXCHANGE', 't.total', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<?php /*<td align="center" class="tablelist" width="75">
							<?php echo JText::_('OWNSERVICE_BRANCH_CODE'); ?>
						</td>
						<td align="center" class="tablelist" width="85">
							<?php echo JText::_('OWNSERVICE_TIME_TRANSFER'); ?>
						</td> */ ?>
					</tr>
					<tfoot>
						<tr>
						  <td colspan="12"><?php echo $this->pageNav->getListFooter(true); ?></td>
						</tr>
					</tfoot>
					<tbody>
					<?php
						$k					= 0;
						$sum_amount	= 0;
						$sum_rate	 	= 0;
						$sum_total		= 0;
						$priceformat	= OwnserviceHelper::getParams('price_format', '#,###.##');
						$dateformat	= OwnserviceHelper::getParams('date_format', '%d/%m/%Y');

						for($i=0,$n=count($this->rows);$i<$n;$i++):
						
						 $row		= $this->rows[$i];
						 $checked	= JHTML::_('grid.checkedout', $row, $i );
					?>
					<tr class="<?php echo "row$k"; ?>"> 
						<td align="center" class="inner_tablelist">
							<?php echo $this->pageNav->getRowOffset( $i ); ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo $checked; ?>
						</td>
						<td align="center" class="inner_tablelist">
							<a href="<?php echo JRoute::_('index.php?option=com_ownservice&controller=transaction&task=detail&id='.$row->id); ?>">
								<?php echo $row->invoice; ?>
							</a>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo OwnserviceHelper::accountFormat($row->account); ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php if($row->abankname=='other'): ?>
								<?php echo $row->bank_other; ?>
							<?php else: ?>
								<?php echo $row->abankname; ?>
							<?php endif; ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo $row->branch_city; ?>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo $row->abranchname; ?>
						</td>
						<td class="inner_tablelist">
							<a href="<?php echo JRoute::_('index.php?option=com_ownservice&controller=member&task=detail&id='.$row->memberid); ?>">
							<?php echo $row->username; ?>
							</a>
						</td>
						<td align="center" class="inner_tablelist">
							<?php echo JHTML::_('date', $row->requested_date, $dateformat); ?>
						</td>
						<td class="inner_tablelist" align="center">
							<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?>
							<?php $sum_amount = $sum_amount + $row->amount; ?>
						</td>
						<td class="inner_tablelist" align="center">
							<?php
								$color = '';
								if($row->extrarate > 0.00 ) {
									$color = 'red';
								} else if($row->extrarate < 0.00) {
									$color = 'green';
								}
							?>
							<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px solid;">
								<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th); ?> THB
							</div>
							<?php endif; ?>
							<div>
								<span class ="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate); ?></span>
								<?php echo $row->rate_code; ?> 
							</div>
						</td>
						<td class="inner_tablelist" align="center">
							<?php if(!$row->iscore): ?>
								<div style="border-bottom: 1px solid;">
									<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
									<?php $sum_total = $sum_total + $row->total_th; ?>
								</div>
							<?php else: ?>
								<?php
									if($row->extratotal > 0.00 ){
										$sum_total = $sum_total + $row->extratotal;	
									} else {
										$sum_total = $sum_total + ( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee));  
									}
								?>
							<?php endif; ?>
							<div>
								<span class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
									<?php 
										if($row->extratotal > 0.00) {
											echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal);
										} else {
											echo OwnserviceHelper::moneyFormat($priceformat,( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))); 
										}
									?>
								</span> <?php echo $row->rate_code; ?>
							</div>
						</td>
					</tr>
					<?php $k = 1 - $k; endfor; ?>
					<tr>
						<td colspan="9" align="right">
							<strong><?php echo JText::_('OWNSERVICE_TOTAL'); ?></strong>
						</td>
						<td align="center" style="font-weight: bold;">
							<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_amount); ?>
						</td>
						<td align="right">
						</td>
						<td align="center" style="font-weight: bold;">
							<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_total). ' THB'; ?>
						</td>
					</tr>
					</tbody>
				</table>
				<input type="hidden" name="boxchecked" value="0" />
				<input type="hidden" name="id" value="" />
				<input type="hidden" name="status" value="" />
				<input type="hidden" name="option" value="com_ownservice" />
				<input type="hidden" name="task" value="requestapproval" />
				<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
				<input type="hidden" name="controller" value="transaction" />
				<input type="hidden" name="view" value="transactions" />
				<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
				<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
				<?php echo JHTML::_( 'form.token' ); ?>
			</form>
		</div>
</div>